package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.domain.MobileExhibitors;
import com.ruoyi.business.service.IMobileExhibitorsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 参展商Controller
 * 
 * @author ruoyi
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/mobile/exhibitors")
public class MobileExhibitorsController extends BaseController {

    @Autowired
    private IMobileExhibitorsService mobileExhibitorsService;

    /**
     * 查询参展商列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MobileExhibitors mobileExhibitors) {
        startPage();
        List<MobileExhibitors> list = mobileExhibitorsService.selectMobileExhibitorsList(mobileExhibitors);
        return getDataTable(list);
    }

    /**
     * 导出参展商列表
     */
    @Log(title = "参展商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MobileExhibitors mobileExhibitors) {
        List<MobileExhibitors> list = mobileExhibitorsService.selectMobileExhibitorsList(mobileExhibitors);
        ExcelUtil<MobileExhibitors> util = new ExcelUtil<MobileExhibitors>(MobileExhibitors.class);
        util.exportExcel(response, list, "参展商数据");
    }

    /**
     * 获取参展商详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id, @RequestParam("openId") String openId) {
        return success(mobileExhibitorsService.selectMobileExhibitorsById(id,openId));
    }

    /**
     * 新增参展商
     */
    @Log(title = "参展商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MobileExhibitors mobileExhibitors) {
        return toAjax(mobileExhibitorsService.insertMobileExhibitors(mobileExhibitors));
    }

    /**
     * 修改参展商
     */
    @Log(title = "参展商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MobileExhibitors mobileExhibitors) {
        return toAjax(mobileExhibitorsService.updateMobileExhibitors(mobileExhibitors));
    }

    /**
     * 删除参展商
     */
    @Log(title = "参展商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mobileExhibitorsService.deleteMobileExhibitorsByIds(ids));
    }

    /**
     * @Author liumaotong
     * @Description 根据地址获取GPS坐标
     * @Date 2024/6/16
     * @Param [mobileExhibitors]
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @RequestMapping("/getGpsByAddress")
    public AjaxResult getGpsByAddress(@RequestBody MobileExhibitors mobileExhibitors){
        logger.info("根据地址获取GPS坐标接口,地址：" + mobileExhibitors.getAddress());
        return AjaxResult.success(mobileExhibitorsService.getGpsByAddress(mobileExhibitors));
    }

}
